<template>
  <div class="container">
    <global-header :user="user"></global-header>
    <loader v-if="isLoading"></loader>
    <!-- <message type="error" :message="error.message"></message> -->
    <router-view></router-view>
    <footer class="text-center py-4 text-secondary bg-light mt-4">
      <small>
        <ul class="list-inline mb-0">
          <li class="list-inline-item">© 2020 者也专栏</li>
          <li class="list-inline-item">课程</li>
          <li class="list-inline-item">文档</li>
          <li class="list-inline-item">联系</li>
          <li class="list-inline-item">更多</li>
        </ul>
      </small>
    </footer>
  </div>
</template>

<script lang="ts">
import { defineComponent, computed, onMounted, watch } from "vue";
import "bootstrap/dist/css/bootstrap.min.css";
import GlobalHeader from "./components/GlobalHeader.vue";
import Loader from "./components/Loader.vue";
import { GlobalDataProps } from "./store";
import { useStore } from "vuex";
import axios from "axios";
import createMessage from "./components/createMessage";
// import Message from "./components/Message.vue";

export default defineComponent({
  name: "App",
  components: {
    GlobalHeader,
    Loader
    // Message
  },
  setup() {
    const store = useStore<GlobalDataProps>();
    const isLoading = computed(() => store.state.loading);
    const currentUser = computed(() => store.state.user);
    const token = computed(() => store.state.token);
    const error = computed(() => store.state.error);
    // onMounted(() => {
    //   const instance = createMessage("111", "success");
    //   // 调用实例身上的destory方法手动的销毁message
    //   setTimeout(() => {
    //     instance.destory();
    //   }, 1000);
    // });
    watch(
      () => error.value.status,
      () => {
        const { status, message } = error.value;
        if (status && message) {
          createMessage(message, "error");
        }
      }
    );
    return {
      user: currentUser,
      isLoading,
      error
    };
  }
});
</script>
